<?php include(dirname(__FILE__) . "/../functions.php"); ?>
<form id="zipform" method="post" action="<?php echo THFRURL; ?>download-zip.php">
  <ol class="graphicol">

    <li>
      <input type="hidden" name="thfruploadpath" value="<?php echo urlencode(THFRUPLOADPATH); ?>"/>
      <strong>Theme Directory Name</strong>: <input type="text" size="30" id="zipdir" name="zipdir" value="<?php
    echo strtolower(str_replace(' ', '-', preg_replace("/[^a-zA-Z0-9\s]/", "", $thfr_css['themename']))); ?>"/>
      <span class="example">Example:</span><code>blue-theme-3</code><span style="padding-left:20px;color:brown">No spaces or special characters.</span>
    </li>

    <li>
      <span style="float:left;font-weight:bold">Choose files:</span>
      <input style="display:none" type="checkbox" id="zipcheckall1" class="zipcheckall" name="zipcheckall1" checked="checked"/>
      <label for="zipcheckall1" class="checkuncheck" id="checkuncheckall">Check/Uncheck All</label>
      <br style="clear:both"/>

      <div class="submenu clearfix">
        <h3>Global files:
          <!--<span class="toggleupdown">&nbsp;</span>-->
        </h3>
        <input style="display:none" type="checkbox" class="checkunchecksection" id="check-globalfiles" name="check-globalfiles" checked="checked"/>
        <label for="check-globalfiles" class="checkuncheck"></label>
      <span class="floatcheckbox">
        <input type="checkbox" id="zipstylecss" name="ziparray[]" value="style.css" checked="checked"/>
        <label for="zipstylecss"><code>style.css</code></label>
      </span>
      <span class="floatcheckbox">
        <input type="checkbox" id="zipjavascript" name="ziparray[]" value="javascript.js" checked="checked"/>
        <label for="zipjavascript"><code>javascript.js</code></label>
      </span>
      <span class="floatcheckbox">
        <input type="checkbox" id="zipfunctions" name="ziparray[]" value="functions.php" checked="checked"/>
        <label for="zipfunctions"><code>functions.php</code></label>
      </span>
	  <span class="floatcheckbox">
	    <input type="checkbox" id="lbheader" name="ziparray[]" value="header.php" checked="checked"/>
		<label for="lbheader"><code>header.php</code></label>
      </span>
	  <span class="floatcheckbox">
	    <input type="checkbox" id="lbfooter" name="ziparray[]" value="footer.php" checked="checked"/>
		<label for="lbfooter"><code>footer.php</code></label>
	  </span>
	  <span class="floatcheckbox">
	    <input type="checkbox" id="lbloop" name="ziparray[]" value="loop.php" checked="checked"/>
		<label for="lbloop"><code>loop.php</code></label>
	  </span>
      <span class="floatcheckbox">
        <input type="checkbox" id="zipcomments" name="ziparray[]" value="comments.php" checked="checked"/>
        <label for="zipcomments"><code>comments.php</code></label>
      </span>
        <!-- <input type="checkbox" name="ziparray[]" value="options.php" checked="checked" /> <code>options.php</code><br /> -->
      </div>

      <div class="submenu clearfix">
        <h3>Page Templates:
          <!--<span class="toggleupdown">&nbsp;</span>-->
        </h3>
        <input style="display:none" type="checkbox" class="checkunchecksection" id="check-pagetemplates" name="check-pagetemplates" checked="checked"/>
        <label for="check-pagetemplates" class="checkuncheck"></label>
        <?php foreach ($thfr_css['pagetemplates'] as $pagetemplate) { ?>
        <span class="floatcheckbox">
          <input type="checkbox" id="zip<?php echo $pagetemplate; ?>" name="ziparray[]" value="<?php echo $pagetemplate; ?>.php" checked="checked"/>
          <label for="zip<?php echo $pagetemplate; ?>"><code><?php echo $pagetemplate; ?>.php</code></label>
        </span>
        <?php } ?>
      </div>

      <?php
// Check which images are used in the CSS:
      $cssImagesArray = array();
      $available_selectors = tf_selectors();
      foreach ($available_selectors as $sel) {
        if (isset($thfr_css[$sel])) {
          if ($thfr_css[$sel]['background-image'] != '') {
            /*
            $cssImagesArray[] = preg_replace("/(.*)url\(\/uploads\/(.*?)\)(.*)/i", "\${2}",
                      $thfr_css[$sel]);
            */
            $cssImagesArray[] = str_replace("/uploads/", "", $thfr_css[$sel]['background-image']);
          }
        }
      }
      $cssImagesArray = array_unique($cssImagesArray);

// Beta 19: Check with images are used as foreground-images
      $foregroundImagesArray = array();
      if (isset($thfr_css['customdropimages'])) {
        foreach ($thfr_css['customdropimages'] as $name => $value) {
          $foregroundImagesArray[] = $value['file'];
        }
      }

      $files = scandir(THFRUPLOADPATH . '/');
      natcasesort($files);
      if (count($files) > 2) { /* The 2 accounts for . and .. */
        // All files
        $imgext = array('jpg', 'JPG', 'JPEG', 'jpeg', 'gif', 'GIF', 'png', 'PNG', 'bmp', 'BMP');
        foreach ($files as $file) {
          if (file_exists(THFRUPLOADPATH . '/' . $file)
            && $file != '.' && $file != '..' && in_array(file_extension($file), $imgext)
            && !is_dir(THFRUPLOADPATH . '/' . $file)
          ) {
            if (in_array($file, $cssImagesArray)) {
              $cssImages[] = $file;
            }
            else {
              $otherImages[] = $file;
            }
          }
        }

        ?><div class="submenu clearfix"><h3>Background Images</h3>
        <?php if (!empty($cssImages)) { ?>
          <!--<span class="toggleupdown">&nbsp;</span>-->
          <input style="display:none" type="checkbox" class="checkunchecksection" id="cssimagecheckall" name="cssimagecheckall" checked="checked"/>
          <label for="cssimagecheckall" class="checkuncheck"></label>
          <?php
          foreach ($cssImages as $image) {
            ?>
            <span class="floatcheckbox">
        <input type="checkbox" id="images-<?php echo $image; ?>" name="ziparray[]" value="images/<?php echo $image; ?>" checked="checked"/>
        <label for="images-<?php echo $image; ?>"><code><?php echo $image; ?></code></label>
      </span>
            <?php
          }
          echo "</div>";
        } else {
          echo "<em>- - none used in this theme - -</em></div>";
        }


        ?><div class="submenu clearfix"><h3>Foreground Images</h3>
        <?php if (!empty($foregroundImagesArray)) { ?>
          <!--<span class="toggleupdown">&nbsp;</span>-->
          <input style="display:none" type="checkbox" class="checkunchecksection" id="otherimagecheckall" name="otherimagecheckall" checked="checked"/>
          <label for="otherimagecheckall" class="checkuncheck"></label>
          <?php
          foreach ($foregroundImagesArray as $image) {
            ?>
            <span class="floatcheckbox">
        <input type="checkbox" id="images-<?php echo $image; ?>" name="ziparray[]" value="images/<?php echo $image; ?>" checked="checked"/>
        <label for="images-<?php echo $image; ?>"><code><?php echo $image; ?></code></label>
      </span>
            <?php
          }
          echo "</div>";
        } else {
          echo "<em>- - none used in this theme - -</em></div>";
        }
      } else {
        echo "You aren't using any custom images in the theme so there's nothing to choose here";
      }
      ?>

      <!--
      <input style="display:none" type="checkbox" id="zipcheckall2" class="zipcheckall" name="zipcheckall2" checked="checked">
      <label for="zipcheckall2" class="checkuncheck" id="checkuncheckall2">Check/Uncheck All</label>
      <br style="clear:both" />
      -->
    </li>

    <li>
      <input type="submit" id="zipsubmit" class="downloadsubmit" value="Download ZIP file"/>
    </li>
  </ol>
</form>

<h2>After you downloaded the ZIP file:</h2>
<h3>Quick How-To:</h3>
(1) Extract the ZIP file, (2) upload the resulting theme directory with all its files
to the <code>/wp-content/themes/</code> directory of your WordPress installation and
(3) activate the theme in the WP Admin area at <code>Appearance &rarr; Themes</code>.
<br/>
<h3>Detailed How-To:</h3>
<ol id="ziphowto" class="graphicol2">
  <li>
    Extract the ZIP-file on your computer. When you double-click or right-click on it, there should be an option
    to "extract", "uncompress" or "unzip" the file in the context menu or wizard that pops up.
    Or else, use a program like <a href="http://www.7-zip.org/download.html">7-zip</a> (Win/Mac, Free).
    <br/>
  </li>
  <li>
    Now you should have a directory on your computer, with the name that you put into "Theme Directory Name"
    (see the form field at the very top of this page).
    <br/>
  </li>
  <li>
    Depending on the ZIP program or Operating System (Windows, Mac) the directory may be <strong>inside</strong>
    another directory. For instance, the built in Extract wizard in Windows XP creates this:<br/><br/>
    <code>/my-new-theme/my-new-theme/</code><br/>
    <code>/my-new-theme/my-new-theme/style.css</code><br/>
    <code>/my-new-theme/my-new-theme/... etc ...</code><br/>
    <br/>
    The extracted directory was put as a "child" directory <strong>inside</strong> a "parent" directory with the same
    name.
    If this happens, make sure you upload only the "child" or "inner" directory in the next step.
    <br/>
  </li>
  <li>
    Upload the theme directory (i.e. <code>/my-new-theme/</code>), with all its files, to the "themes" directory of your
    WordPress installation, which usually is
    <code>/wp-content/themes/</code> so that you end up with:<br/><br/>
    <code>/wp-content/themes/my-new-theme/</code><br/>
    <code>/wp-content/themes/my-new-theme/style.css</code><br/>
    <code>/wp-content/themes/my-new-theme/index.php</code><br/>
    <code>/wp-content/themes/my-new-theme/... etc ...</code><br/>
  </li>
  <li>
    Choose and activate the theme in the WordPress admin area, at <code>Appearance &rarr; Themes</code>
  </li>
</ol>
